from telethon import TelegramClient

from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.functions.channels import GetAdminLogRequest

from telethon.tl.types import InputChannel
from telethon.tl.types import ChannelAdminLogEventsFilter
from telethon.tl.types import InputUserSelf
from telethon.tl.types import InputUser

# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = 96038 # Your api_id
api_hash = 'ac7126a6832100e780ac6e8d12e09637' # Your api_hash
phone_number = '+8615982409200' # Your phone number

client = TelegramClient(phone_number, api_id, api_hash)
client.session.report_errors = False
client.connect()

if not client.is_user_authorized():
    print('not client.is_user_authorized')
    client.send_code_request(phone_number)
    client.sign_in(phone_number, input('Enter the code: '))
    
    channel = client(ResolveUsernameRequest('Coin2World')) # Your channel username

user = client(ResolveUsernameRequest('Tom Tao')) # Your channel admin username
admins = [InputUserSelf(), InputUser(user.users[0].id, user.users[0].access_hash)] # admins
admins = [] # No need admins for join and leave and invite filters

filter = None # All events
# param: (join, leave, invite, ban, unban, kick, unkick, promote, demote, info, settings, pinned, edit, delete)
filter = ChannelAdminLogEventsFilter(True, True, True, False, False, False, False, False, False, False, False, False, False, False)

result = client(GetAdminLogRequest(InputChannel(channel.chats[0].id, channel.chats[0].access_hash), '', 0, 0, 10, filter, admins))
##print(result)

for _user in result.users:
    ##print(_user.id)
    with open(''.join(['users/', str(_user.id)]), 'w') as f:
        f.write(str(_user.id))